package com.hpf.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hpf.lease.common.config.CommonException;
import com.hpf.lease.common.result.ResultCodeEnum;
import com.hpf.lease.model.bean.PaymentType;
import com.hpf.lease.web.admin.mapper.PaymentTypeMapper;
import com.hpf.lease.web.admin.service.PaymentTypeService;
import org.springframework.stereotype.Service;

/**
* @author GOD
* @description 针对表【payment_type(支付方式表)】的数据库操作Service实现
* @createDate 2024-08-29 15:00:50
*/
@Service
public class PaymentTypeServiceImpl extends ServiceImpl<PaymentTypeMapper, PaymentType>
    implements PaymentTypeService {

    @Override
    public boolean saveOrUpdatePaymentType(PaymentType paymentType) {
        Long id = paymentType.getId() == null ? -1 : paymentType.getId();
        PaymentType oneType = this.getOne(Wrappers.lambdaQuery(PaymentType.class)
                .eq(PaymentType::getName, paymentType.getName()).last("limit 1")
        );
        if (oneType != null && !id.equals(oneType.getId()))
            throw new CommonException(ResultCodeEnum.PAYMENT_TYPE_EXISTS_ERROR);
        return this.saveOrUpdate(paymentType);
    }

}




